package `in`.hocg.intellij.codeview.action

import `in`.hocg.intellij.codeview.service.AppsService
import `in`.hocg.intellij.codeview.ui.BalloonNotifications
import com.intellij.ide.CopyPasteManagerEx
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import java.awt.datatransfer.DataFlavor

/**
 * Created by hocgin on 2019/12/26.
 * email: hocgin@gmail.com
 * 分享粘贴板内容
 * @author hocgin
 */
class ShareClipboardAction : AnAction() {
    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return
        val text = CopyPasteManagerEx.getInstance()?.getContents<String>(DataFlavor.stringFlavor)
        if (text == null
            || text.isBlank()
        ) {
            BalloonNotifications.showWarningNotification("请选中要分享的内容")
            return
        }

        AppsService.shareTextAndNotify(
            content = text,
            project = project
        )
    }
}